package com.lz.controller;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

/**
 * @Package com.lz.controller
 * @Project currency-trading
 * @Author lenovo
 * @Date 2022/1/6 10:57
 * @Describe TODO
 * @Version V1.0
 */
@RestController
public class UserInfoController {

    /**
     * @MethName userInfo
     * @Params [java.security.Principal]
     * @Return java.security.Principal
     * @Author lenovo
     * @Date 2022/1/6 10:58
     * @Describe 根据token(Authorization)获取当前登录的用户对象(Principal)
     */
    @GetMapping("/user/info")
    public Principal userInfo(Principal principal) {
        // 使用ThreadLocal实现的
        // Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return principal;
    }
}
